﻿using System;
using System.Collections.Generic;
using Duo1JHttpServer.Framework.Interface;
using Duo1JHttpServer.Framework.Model;
using Duo1JHttpServer.Framework.Utils;

namespace Duo1JHttpServer.Framework.Config
{
    /// <summary>
    /// 过滤器配置
    /// </summary>
    public class FilterConfig
    {
        private List<FilterConfigModel> filterModels;
        private readonly Dictionary<string, IHttpFilter> filterDic = new Dictionary<string, IHttpFilter>();

        /// <summary>
        /// 映射处理器模型
        /// </summary>
        public List<FilterConfigModel> FilterModels
        {
            get { return filterModels; }
            set
            {
                filterModels = value;
                ConsoleUtils.WriteYellowLine("Refresh-FilterConfig");
                FilterDic.Clear();
                foreach (FilterConfigModel model in filterModels)
                {
                    if (model.Filter != null)
                    {
                        FilterDic.Add(model.Url, model.Filter);
                        ConsoleUtils.WriteTabLine($"Request Url add: {model.Url}");
                    }
                }
            }
        }

        /// <summary>
        /// 请求与处理器映射
        /// </summary>
        public Dictionary<string, IHttpFilter> FilterDic
        {
            get { return filterDic; }
        }
    }
}